package fr.upmc.i3s.upmcontact.views.dialogs;

import fr.upmc.i3s.upmcontact.R;
import fr.upmc.i3s.upmcontact.contents.UpmcInfo;
import fr.upmc.i3s.upmcontact.tools.BitmapFactoryAdapter;
import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;

public class UpmcInfoDetailsDialog extends Activity {
	
	private static final String TAG = "UpmcInfoDetailsDialog";
	
	public static String PARAM_INFO = "UpmcInfoDetailsDialog.object";
	
	private UpmcInfo ui;
	private int activityWidth;

	private TextView tvTitle;
	private TextView tvRecipients;
	private ImageView ivPhoto;
	private TextView tvDescription;
	private TextView tvLink;
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_upmc_info);
        
        // set dialog size (90% screen width) :
        DisplayMetrics metrics = getResources().getDisplayMetrics();
        this.activityWidth = (int) (metrics.widthPixels * 0.90);
        getWindow().setLayout(activityWidth, LayoutParams.WRAP_CONTENT);
        
        // get extras parameters 
        this.ui = null;
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
        	this.ui = (UpmcInfo) extras.getSerializable(PARAM_INFO);
        }
        Log.d(TAG, "extras.UpmcInfo = "+ui);
        
        fetchViews();
        customizeViews();
        setListeners();
	}
	
	private void fetchViews() {
		this.tvTitle = (TextView) this.findViewById(R.id.textView_dialog_title);
		this.tvRecipients = (TextView) this.findViewById(R.id.textView_dialog_recipients);
		this.ivPhoto = (ImageView) this.findViewById(R.id.imageView_dialog_photo);
		this.tvDescription = (TextView) this.findViewById(R.id.textView_dialog_description);
		this.tvLink = (TextView) this.findViewById(R.id.textView_dialog_link);
	}
	
	private void customizeViews() {
		if(ui != null) {
			this.tvTitle.setText(ui.getTitle());
			this.tvRecipients.setText(getString(R.string.display_to_recipients)+" "+ui.getRecipients());
	 		if(ui.getPhotoPath() != null) { 
	 			Bitmap bm = BitmapFactoryAdapter.decodeFile(ui.getPhotoPath(), 400);
	 			ivPhoto.setImageBitmap(bm);
	 		}
	 		this.ivPhoto.setAdjustViewBounds(true);
			this.tvDescription.setText(ui.getDescription()); 
			this.tvLink.setText(ui.getLink());
		}
	}
	
	private void setListeners() {
		
	}
	
}
